package cn.jiahua.hospital.service.impl;

import cn.jiahua.hospital.dto.PayDoctorDto;
import cn.jiahua.hospital.mapper.PayDoctorMapper;
import cn.jiahua.hospital.pojo.PayDoctor;
import cn.jiahua.hospital.service.PayDoctorService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.ArrayList;
import java.util.HashMap;

import cn.jiahua.hospital.dto.Page;
import cn.jiahua.hospital.constants.Constants;

import javax.annotation.Resource;

@Service
public class PayDoctorServiceImpl implements PayDoctorService {

    @Resource
    private PayDoctorMapper payDoctorMapper;

    @Override
    public PayDoctor getPayDoctorById(Integer id) {
        return payDoctorMapper.getPayDoctorById(id);
    }

    @Override
    public List<PayDoctor> getPayDoctorListByMap(Map<String, Object> param) {
        return payDoctorMapper.getPayDoctorListByMap(param);
    }

    @Override
    public Integer getPayDoctorCountByMap(Map<String, Object> param) {
        return payDoctorMapper.getPayDoctorCountByMap(param);
    }

    @Override
    public Integer qdtxAddPayDoctor(PayDoctor payDoctor) {
        payDoctor.setPayDoctorCreateTime(new Date());
        return payDoctorMapper.insertPayDoctor(payDoctor);
    }

    @Override
    public Integer qdtxModifyPayDoctor(PayDoctor payDoctor) {
        payDoctor.setPayDoctorCreateTime(new Date());
        return payDoctorMapper.updatePayDoctor(payDoctor);
    }

    @Override
    public Integer qdtxDeletePayDoctorById(Integer id) {
        return payDoctorMapper.deletePayDoctorById(id);
    }

    @Override
    public Integer qdtxBatchDeletePayDoctor(String ids) {
        Map<String, List<String>> param = new HashMap<String, List<String>>();
        String[] paramArrays = ids.split(",");
        List<String> idList = new ArrayList<String>();
        for (String temp : paramArrays) {
            idList.add(temp);
        }
        param.put("ids", idList);
        return payDoctorMapper.batchDeletePayDoctor(param);
    }

    @Override
    public Page<PayDoctor> queryPayDoctorPageByMap(Map<String, Object> param, Integer pageNo, Integer pageSize) {
        Integer total = payDoctorMapper.getPayDoctorCountByMap(param);
        pageNo = pageNo == null ? Constants.DEFAULT_PAGE_NO : pageNo;
        pageSize = pageSize == null ? Constants.DEFAULT_PAGE_SIZE : pageSize;
        Page page = new Page(pageNo, pageSize, total);
        param.put("beginPos", page.getBeginPos());
        param.put("pageSize", page.getPageSize());
        List<PayDoctor> payDoctorList = payDoctorMapper.getPayDoctorListByMap(param);
        page.setList(payDoctorList);
        return page;
    }

    @Override
    public Page<PayDoctorDto> getPayDoctorPage(Map<String, Object> param, Integer pageNo, Integer pageSize) {
        Integer total = payDoctorMapper.getPayDoctorCount((Integer) param.get("userId"));
        pageNo = pageNo == null ? Constants.DEFAULT_PAGE_NO : pageNo;
        pageSize = pageSize == null ? Constants.DEFAULT_PAGE_SIZE : pageSize;
        Page page = new Page(pageNo, pageSize, total);
        param.put("beginPos", page.getBeginPos());
        param.put("pageSize", page.getPageSize());
        List<PayDoctorDto> payDoctor = payDoctorMapper.getPayDoctor(param);
        page.setList(payDoctor);
        return page;
    }
}